package com.googlecode.afdbaccess.web.touch.webcontent.list_rows.list_rows_table_data;

import javax.annotation.security.RolesAllowed;
import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;

import org.jboss.resteasy.annotations.cache.Cache;

import com.googlecode.afdbaccess.config.injectconfig.ManagedRequestTransaction;
import com.googlecode.afdbaccess.web.common.interceptors.DatabaseAccessing;
import com.googlecode.afdbaccess.web.common.interceptors.RequestLogged;

@RolesAllowed("theRole")
@RequestLogged
@DatabaseAccessing
@Path("list-rows/list-rows-table-data")
public class ListRowsTableGetRest {
    @Inject
    private ManagedRequestTransaction t;

    @GET
    @Cache(maxAge=0)
    @Produces("application/json")
    public String get(@SuppressWarnings("unused") @Context HttpServletRequest request) throws Exception {
        String sql = "";
        sql += "SELECT\n";
        sql += "  webTable.webTable_id id,\n";
        sql += "  webTable.stringAttribute\n";
        sql += "FROM\n";
        sql += "  webTable\n";
        sql += "ORDER BY\n";
        sql += "  webTable.webTable_id";

        String jsonString = t.executeJsonObjectsInArrayQuery(sql, null, 0);
        
        return "{\"success\":true,\"data\":" + jsonString + "}";
    }
}
